<template>
  <div class="register">
    <section class="form_container">
      <div class="manage_tip">
        <span class="title">二手坤后台-注册</span>
      </div>
      <el-form
        :model="registerUser"
        :rules="rules"
        class="registerForm"
        ref="registerForm"
        label-width="100px"
      >
        <el-form-item calss="item" prop="name">
          <span slot="label">
            <span style="color: white">用户名</span>
          </span>
          <el-input
            v-model="registerUser.name"
            placeholder="请输入用户名"
            style="opacity: 0.8"
          ></el-input>
        </el-form-item>

        <el-form-item calss="item" prop="password">
          <span slot="label">
            <span style="color: white">密码</span>
          </span>
          <el-input
            v-model="registerUser.password"
            placeholder="请输入密码"
            type="password"
            style="opacity: 0.8"
          >
          </el-input>
        </el-form-item>

        <el-form-item calss="item" prop="confirmPassword">
          <span slot="label">
            <span style="color: white">确认密码</span>
          </span>
          <el-input
            v-model="registerUser.confirmPassword"
            placeholder="请再次输入密码"
            type="password"
            style="opacity: 0.8"
          >
          </el-input>
        </el-form-item>

        <el-form-item calss="item">
          <span slot="label">
            <span style="color: white">注册类型</span>
          </span>
          <el-select v-model="registerUser.identify" placeholder="请选择身份">
            <el-option label="超级管理员" value="超级管理员"></el-option>
            <el-option label="管理员" value="管理员"></el-option>
            <el-option label="员工" value="员工"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            class="submit_btn"
            @click="submitForm('registerForm')"
            >注册</el-button
          >
        </el-form-item>
      </el-form>
    </section>
  </div>
</template>

<script>
import jwt_decode from "jwt-decode";
export default {
  name: "register",

  data() {
    var validatePass2 = (rule, value, callback) => {
      if (value !== this.registerUser.password) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };
    return {
      registerUser: {
        name: "",
        // email: "",
        password: "",
        confirmPassword: "",
        // password2: "",
        identify: "",
      },
      rules: {
        name: [
          { required: true, message: "用户名不能为空", trigger: "change" },
          {
            min: 2,
            max: 30,
            message: "长度在 2 到 30 个字符",
            trigger: "blur",
          },
        ],

        password: [
          { required: true, message: "密码不能为空", trigger: "blur" },
          {
            min: 6,
            max: 30,
            message: "长度在 6 到 30 个字符",
            trigger: "blur",
          },
        ],

        confirmPassword: [
          { required: true, message: "密码不能为空", trigger: "blur" },
          {
            min: 6,
            max: 30,
            message: "长度在 6 到 30 个字符",
            trigger: "blur",
          },
          { validator: validatePass2, trigger: "blur" },
        ],
        // identify:[{required: true, trigger: "blur"}]
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$axios
            .post("/admin/register", this.registerUser)
            .then((res) => {
              this.$message.success("恭喜，注册成功！");
              this.$router.push("/login");
            })
            .catch((err) => {
              // console.log(err)
              this.$message.error("注册失败！");
            });
        } else {
          this.$message({
            type: "error",
            message: "错误提交申请",
          });
          return false;
        }
      });
    },
  },
};
</script>


<style lang="less" scoped>
.register {
  position: relative;
  width: 100%;
  height: 100%;
  background: url(../../assets/images/logo.jpg) no-repeat center center;
  background-size: 100% 100%;
}

.form_container {
  width: 370px;
  height: 210px;
  position: absolute;

  padding: 25px;
  border-radius: 5px;
  text-align: center;
  left: 40.2%;
  top: 25%;
  opacity: 0.8;
}

.form_container .manage_tip .title {
  font-family: "Microsoft YaHei";
  font-weight: bold;
  font-size: 26px;
  color: #fff;
}

.registerForm {
  margin-top: 20px;
  // background-color: #fff;
  padding: 20px 40px 20px 20px;
  border-radius: 5px;
  box-shadow: 0px 5px 10px #cccc;
  background-color: rgb(94, 90, 90);
  // opacity: 0.5;
}

.submit_btn {
  width: 100%;
}

.tiparea {
  text-align: right;
  font-size: 12px;
  color: #fff;
}

.item .el-form-item__label {
  color: #fff;
}

.tiparea p a {
  color: #409eff;
}

// 改变input里的字体颜色
/deep/input::-webkit-input-placeholder {
  color: white;
  font-size: 15px;
}

// 改变input框背景颜色
/deep/.el-input__inner {
  background-color: transparent !important;
  // background-color:#4d4f50;
  color: white; // 输入字体颜色
  // opacity: 0.5;
  border: 1px solid white;
}
</style>
    